package com.education.welco.controller;


import com.education.common.core.BaseController;
import com.education.common.pojo.AjaxResult;
import com.education.common.utils.ApiReturnObject;
import com.education.common.utils.StringUtils;
import com.education.utils.BaiduAipContentCensor;
import com.education.welco.pojo.*;
import com.education.welco.pojo.vo.MessageList;
import com.education.welco.service.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 教师答疑 信息操作处理 上课资料 课程问答
 *
 * @author d
 * @date 2020-05-08
 */
@RestController
@RequestMapping("/sAnswering")
public class SAnsweringController extends BaseController {

    @Autowired
    private ISAnsweringService answeringService;
    @Autowired
    private ISCatalogAnsweringSynService catalogAnsweringSynService;
    @Autowired
    private ISQueansClassService queansClassService;
    @Autowired
    private ITClassService classService;
    @Autowired
    private ITSchooldeptService schooldeptService;
    @Autowired
    private ISCatalogService catalogService;
    @Autowired
    private ISCatalogMenuService catalogMenuService;
    @Autowired
    private ISAnsweringCommentService sAnsweringCommentService;
    @Autowired
    private BaiduAipContentCensor baiduAipContentCensor;

    //消息通知列表  1.根据教师用户id获取答疑列表  2. 依据答疑列表id数组  在评论表中查询一级评论信息

    /**
     * 老师id
     *
     * @param teaId
     * @return
     */
    @GetMapping("/messageList")
    @ApiOperation(value = "查询二级目录下的答疑列表", httpMethod = "GET")
    public AjaxResult sAnsweringList(@RequestParam(value = "teaId", required = true) Integer teaId,
                                     @RequestParam(value = "pageNum", required = false) Integer pageNum,
                                     @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        //根据老师id查询答疑列表
        SAnswering sAnswering = new SAnswering();
        sAnswering.setUserId(teaId);
        List<SAnswering> sAnsweringList = answeringService.selectSAnsweringList(sAnswering);
        //流转换对象
        List<Integer> twoIntList = sAnsweringList.stream().map(a -> a.getId()).collect(Collectors.toList());
        //根据答疑id查找评论
        if (pageNum != null && pageSize != null) {
            PageHelper.startPage(pageNum, pageSize);
        }
        List<MessageList> messageLists = sAnsweringCommentService.selectCommentListBySAnswerId(twoIntList);
        PageInfo<MessageList> pageInfo = new PageInfo<>(messageLists);
        return AjaxResult.success(pageInfo);
    }

    //消息详情中的评论
    @GetMapping("/messageComment")
    @ApiOperation(value = "查找答疑详情评论", httpMethod = "GET")
    public AjaxResult messageComment(@RequestParam(value = "answerId", required = true) String answerId,
                                     @RequestParam(value = "userId", required = false) String userId,
                                     @RequestParam(value = "type", required = true) String type) {
        return sAnsweringCommentService.selectCommentListById2(answerId, userId, type);
    }

    /**
     * 获取到最上面一级的id     查看班级列表 课程分享班级
     */
    public Integer GetFirstId2(Integer catalogId) {
        SCatalogMenu sCatalogMenu = catalogMenuService.selectSCatalogMenuById(catalogId);
        //第二级
        if (sCatalogMenu.getParentId() != 0) {
            //第一级
            SCatalogMenu sCatalogMenu1 = catalogMenuService.selectSCatalogMenuById(sCatalogMenu.getParentId());
            return GetFirstId2(sCatalogMenu1.getId());
        }
        return sCatalogMenu.getId();
    }

    /**
     * 根据班级查询其部门信息
     */
    public List<TClass> findDept(List<TClass> classList) {
        if (classList.size() > 0) {
            for (TClass tClass : classList) {
                TSchooldept schooldept = schooldeptService.selectTSchooldeptByClassId(tClass.getDeptId());
                //选择在授班级时上级部门查询错误修改
                if (StringUtils.isNotNull(schooldept)) {
                    tClass.setDeptId(schooldept.getId());
                    tClass.setDeptName(schooldept.getDeptName());
                }
            }
        }
        return classList;
    }

    /**
     * 查看班级
     */
    @GetMapping("/answerClass")
    public ApiReturnObject answerClass(Integer catalogId) {
        if (catalogId != null) {
            List<TClass> classList = classService.selectTClassByCatalogIdAnswerAll(catalogId);
            if (classList != null && classList.size() > 0) {
                List<TClass> dept = findDept(classList);
                return new ApiReturnObject("200", "查询成功", dept);
            }
            return new ApiReturnObject("200", "结果为空", classList);
        }
        return new ApiReturnObject("201", "缺少参数", "");
    }

    /**
     * 修改查看班级
     */
    @PostMapping("/updateClass")
    public ApiReturnObject updateClass(@RequestBody SAnswering answering) {
        //answeringId             classList
        if (answering.getId() != null) {
            SQueansClass queansClass = new SQueansClass();
            queansClass.setAnsweringId(answering.getId());
            //先删除中间表数据
            queansClassService.deleteSQueansClassByCatalogId(answering.getId());
            if (answering.getClassList() != null && answering.getClassList().size() > 0) {
                queansClass.setCreateTime(new Date());
                for (TClass tClass : answering.getClassList()) {
                    queansClass.setClassId(tClass.getId());
                    queansClassService.insertSQueansClass(queansClass);
                }
            }
            return new ApiReturnObject("200", "修改成功", "");
        }
        return new ApiReturnObject("201", "缺少catalogId", "");
    }


    /**
     * 查看班级  2
     */
    /*public List<TClass> answerClass2(Integer answeringId) {
        //根据查看内容 查询 查看班级
        List<TClass> classList = classService.selectTClassByCatalogIdAnswerAll(answeringId);
        List<TClass> dept = new ArrayList<>();
        if (classList != null && classList.size() > 0) {
            dept = findDept(classList);
            return dept;
        }
        return dept;
    }*/

    /**
     * 查看内容 针对于左侧目录  1
     */
    @GetMapping("/ansContent")
    public ApiReturnObject ansContent(Integer catalogId) {
        //查出该目录下的所有课程问答     将选中的属性设置为true
        if (catalogId != null) {
            //全部内容集合
            SAnswering answering = new SAnswering();
            answering.setCatalogId(catalogId);
            List<SAnswering> answeringList = answeringService.selectSAnsweringList(answering);
            //选中内容集合
            List<SAnswering> sAnswerings = answeringService.selectSAnsweringBycatalogId(catalogId);
            if (sAnswerings != null && sAnswerings.size() > 0) {
                for (SAnswering sAnswering : sAnswerings) {
                    for (SAnswering sAnswering1 : answeringList) {
                        if (sAnswering.getId().equals(sAnswering1.getId())) {
                            sAnswering1.setChecked(true);
                        }
                    }
                }
            }
            return new ApiReturnObject("200", "查询成功", answeringList);
        }
        return new ApiReturnObject("201", "缺少参数", "");
    }


    /**
     * 点击目录查询课程下的答疑列表
     */
    @GetMapping("/answeringList")
    public ApiReturnObject answeringList(Integer catalogId, String likeName) {
        //查出该目录下的所有课程问答     将选中的属性设置为true
        if (catalogId != null) {
            //全部内容集合
            SAnswering answering = new SAnswering();
            answering.setCatalogId(catalogId);
            answering.setProblemTitle(likeName);
            //格式化创建时间
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<SAnswering> answeringList = answeringService.selectSAnsweringList(answering);
            for (SAnswering one : answeringList) {
                List<Integer> countEachAnswerTalkNum = sAnsweringCommentService.countEachAnswerTalkPeopleNum(one.getId());
                //Integer countEachAnswerTalkNum = sAnsweringCommentService.countEachAnswerTalkNum(sAnswering.getId());
                one.setTotal(countEachAnswerTalkNum.size());
                //查询可以查看的班级集合
                /*List<TClass> classList = answerClass2(one.getId());
                if (classList != null && classList.size() > 0) {
                    String s = "";
                    int size = classList.size();
                    //拼接查看班级字符串
                    for (int i = 0; i < size; i++) {
                        if (i == size - 1) {
                            //最后一个
                            s = s + classList.get(i).getClassName();
                        } else {
                            s = s + classList.get(i).getClassName() + ",";
                        }
                    }
                    one.setClassString(s);
                } else {
                    one.setClassString("");
                }*/
                //格式化时间
                if (one.getCreateTime() != null) {
                    String format = simpleDateFormat.format(one.getCreateTime());
                    one.setCreateTimeString(format);
                }
                if (one.getAttendTime() != null) {
                    one.setAttendTimeString(simpleDateFormat.format(one.getAttendTime()));
                }
                if (one.getEndTime() != null) {
                    one.setEndTimeString(simpleDateFormat.format(one.getEndTime()));
                }
            }
            return new ApiReturnObject("200", "查询成功", answeringList);
        }
        return new ApiReturnObject("201", "缺少参数", "");
    }


    /**
     * 修改查看内容
     */
    @PostMapping("/updateContent")
    public ApiReturnObject updateContent(@RequestBody SAnswering answering) {
        //catalogId     type        classList
        if (answering.getCatalogId() != null) {
            SCatalogAnsweringSyn answeringSyn = new SCatalogAnsweringSyn();
            answeringSyn.setCatalogId(answering.getCatalogId());
            List<SCatalogAnsweringSyn> sCatalogAnsweringSyns = catalogAnsweringSynService.selectSCatalogAnsweringSynList(answeringSyn);
            //中间表中存在数据
            if (sCatalogAnsweringSyns != null && sCatalogAnsweringSyns.size() > 0) {
                // 改变往中间添加的数据的状态
                SAnswering sAnswering = answeringService.selectSAnsweringById(sCatalogAnsweringSyns.get(0).getAnsweringId());
                //根据中间表id 获取数据
                if (sAnswering != null) {
                    //选中内容的id集合     传过来的是id集合
                    if (answering.getAnsweringList() != null && answering.getAnsweringList().size() > 0) {
                        //新建一个集合
                        ArrayList<Integer> list = new ArrayList<>();
//                        List<SAnswering> answeringList = answeringService.selectSAnsweringByIds(answering.getAnswerIdList());
                        for (SAnswering answering1 : answering.getAnsweringList()) {
                            //修改状态
                            answering1.setIsStu(sAnswering.getIsStu());
                            answering1.setSynch(sAnswering.getSynch());
                            //进行修改
                            answeringService.updateSAnswering(answering1);
                            //查看内容的id
                            list.add(answering1.getId());
                        }
                        //没有选择的内容 将状态重置为 0 0
                        SAnswering catalogPreview = new SAnswering();
                        catalogPreview.setCatalogId(answering.getCatalogId());
                        //该目录全部预习内容
                        List<SAnswering> previews = answeringService.selectSAnsweringList(catalogPreview);
                        for (SAnswering sCatalogPreview : previews) {
                            //如果查看内容里不包括当前预习内容 修改其状态
                            if (!list.contains(sCatalogPreview.getId())) {
                                SAnswering preview2 = answeringService.selectSAnsweringById(sCatalogPreview.getId());
                                preview2.setSynch("0");
                                preview2.setIsStu("0");
                                answeringService.updateSAnswering(preview2);
                            }
                        }

                        //先删除中间表数据
                        queansClassService.deleteSQueansClassByCatalogId(answering.getCatalogId());
                        if (answering.getClassList() != null && answering.getClassList().size() > 0) {
                            SQueansClass queansClass = new SQueansClass();
                            queansClass.setAnsweringId(answering.getId());
                            queansClass.setCreateTime(new Date());
                            for (TClass tClass : answering.getClassList()) {
                                queansClass.setClassId(tClass.getId());
                                queansClassService.insertSQueansClass(queansClass);
                            }
                        }
                    } else {
                        //没有选择查看内容 将该状态重置为 0 0
                        SAnswering catalogPreview = new SAnswering();
                        catalogPreview.setCatalogId(answering.getCatalogId());
                        List<SAnswering> previews = answeringService.selectSAnsweringList(catalogPreview);
                        for (SAnswering sCatalogPreview : previews) {
                            sCatalogPreview.setIsStu("0");
                            sCatalogPreview.setSynch("0");
                            answeringService.updateSAnswering(sCatalogPreview);
                        }
                    }
                }
                //删除中间表数据
                catalogAnsweringSynService.deleteSCatalogAnsweringSynByCatalogId(answering.getCatalogId());
            } else {
                //中间表中没有查看内容 将其目录下的所有内容的状态重置为 0 0
                SAnswering catalogPreview = new SAnswering();
                catalogPreview.setCatalogId(answering.getCatalogId());
                List<SAnswering> previews = answeringService.selectSAnsweringList(catalogPreview);
                for (SAnswering sCatalogPreview : previews) {
                    sCatalogPreview.setIsStu("0");
                    sCatalogPreview.setSynch("0");
                    answeringService.updateSAnswering(sCatalogPreview);
                }
            }
            //中间表添加数据
            if (answering.getAnsweringList() != null && answering.getAnsweringList().size() > 0) {
                answeringSyn.setCreateTime(new Date());
                for (SAnswering answering2 : answering.getAnsweringList()) {
                    answeringSyn.setAnsweringId(answering2.getId());
                    catalogAnsweringSynService.insertSCatalogAnsweringSyn(answeringSyn);
                }
            }
            return new ApiReturnObject("200", "修改成功", "");
        }
        return new ApiReturnObject("201", "缺少参数", "");
    }

    /**
     * 查看内容 针对于左侧目录  1
     */
    public List<SAnswering> lookContent(Integer catalogId) {
        List<SAnswering> sAnswerings = answeringService.selectSAnsweringBycatalogId(catalogId);
        return sAnswerings;
    }


    /**
     * list
     */
    @GetMapping("/list")
    public ApiReturnObject list(SAnswering answering) {
        answering.setSynch("1");
        List<SAnswering> answeringList = answeringService.selectSAnsweringList(answering);
        return new ApiReturnObject("200", "查询成功", answeringList);
    }


    /**
     * 查询课程问答列表
     */
    @GetMapping("/listAll")
    public ApiReturnObject listAll(Integer catalogId) {
        //  查看班级字符串  查看内容字符串  是否同步  学生查看    名称拼接
        //根据当前id 查询出列表
        if (catalogId != null) {
            SAnswering answering = new SAnswering();
            answering.setCatalogId(catalogId);

            HashMap<String, Object> map = new HashMap<>();
            //查询可以查看的班级集合
            /*List<TClass> classList = answerClass2(catalogId);
            map.put("classList", classList);
            if (classList != null && classList.size() > 0) {
                String s = "";
                int size = classList.size();
                //拼接查看班级字符串
                for (int i = 0; i < size; i++) {
                    if (i == size - 1) {
                        //最后一个
                        s = s + classList.get(i).getClassName();
                    } else {
                        s = s + classList.get(i).getClassName() + ",";
                    }
                }
                map.put("classString", s);
            } else {
                map.put("classString", null);
            }*/
            //查看内容字符串
            List<SAnswering> resList = lookContent(catalogId);
            map.put("resList", resList);
            if (resList != null && resList.size() > 0) {
                String s = "";
                int size = resList.size();
                //拼接查看班级字符串
                for (int i = 0; i < size; i++) {
                    if (i == size - 1) {
                        //最后一个
                        s = s + resList.get(i).getProblemTitle();
                    } else {
                        s = s + resList.get(i).getProblemTitle() + ",";
                    }
                }
                map.put("resString", s);
                SAnswering sAnswering = resList.get(0);
                //是否同步
                if (sAnswering.getSynch() != null) {
                    if ("0".equals(sAnswering.getSynch())) {
                        map.put("synchBool", false);
                    } else if ("1".equals(sAnswering.getSynch())) {
                        map.put("synchBool", true);
                    }
                } else {
                    map.put("synchBool", false);
                }
                //是否允许学生查看
                if (sAnswering.getIsStu() != null) {
                    if ("0".equals(sAnswering.getIsStu())) {
                        map.put("stuBool", false);
                    } else if ("1".equals(sAnswering.getIsStu())) {
                        map.put("stuBool", true);
                    }
                } else {
                    map.put("stuBool", false);
                }
            } else {
                map.put("synchBool", false);
                map.put("stuBool", false);
                map.put("resString", null);
            }

            //资源的分类
            List<SAnswering> answeringList = answeringService.selectSAnsweringList(answering);

            //格式化创建时间
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (SAnswering sAnswering : answeringList) {
                //格式化时间
                String format = simpleDateFormat.format(sAnswering.getCreateTime());
                sAnswering.setCreateTimeString(format);
            }
            map.put("answeringList", answeringList);
            return new ApiReturnObject("200", "查询成功", map);
        }
        return new ApiReturnObject("201", "缺少catalogId", "");
    }


    /**
     * 详情
     */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id) {
        if (id != null) {
            SAnswering sAnswering = answeringService.selectSAnsweringById(id);
            return new ApiReturnObject("200", "查询成功", sAnswering);
        }
        return new ApiReturnObject("201", "缺少参数", "");
    }


    /**
     * 新增课程问答
     */
    /**
     * 备课模块-课堂答疑新增
     *
     * @param answering
     * @return
     * @throws ParseException
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody SAnswering answering) throws ParseException {
        //具体课程  老师id
        if (answering.getCatalogId() != null && answering.getUserId() != null && answering.getAttendTimeString() != null && answering.getEndTimeString() != null) {
            //添加时只添加信息
            //answering.setIsdisplay("1");
            //默认不允许学生查看
            //answering.setIsStu("1");
            //默认不进行同步
            //answering.setSynch("0");
            //设置创建日期
            answering.setCreateTime(new Date());

            //开始日期和结束日期格式化日期-将字符串日期转换为日期类型
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            answering.setAttendTime(format.parse(answering.getAttendTimeString()));
            answering.setEndTime(format.parse(answering.getEndTimeString()));
            //检测problemTitle是否符合规范
            if (org.apache.commons.lang3.StringUtils.isNotBlank(answering.getProblemTitle())) {
                int i = baiduAipContentCensor.AipText(answering.getProblemTitle());
                if (i == 2) {
                    return new ApiReturnObject("201", "您新增的课堂答疑中出现不当言论,请检查后再次提交", "您新增的课堂答疑中出现不当言论,请检查后再次提交");
                }
            }
            answeringService.insertSAnswering(answering);
            //改版后不存在班级分享逻辑
            /*SQueansClass queansClass = new SQueansClass();
            queansClass.setAnsweringId(answering.getId());
            //先删除中间表数据
            queansClassService.deleteSQueansClassByCatalogId(answering.getId());
            if (answering.getClassList() != null && answering.getClassList().size() > 0) {
                queansClass.setCreateTime(new Date());
                for (TClass tClass : answering.getClassList()) {
                    queansClass.setClassId(tClass.getId());
                    queansClassService.insertSQueansClass(queansClass);
                }
            }*/
            return new ApiReturnObject("200", "添加成功", "");
        }
        return new ApiReturnObject("201", "缺少catalogId", "");

    }

    @GetMapping("/selectCommentListById")
    public ApiReturnObject selectCommentListById(String id, String userId, String type) {
        answeringService.selectCommentListById(id, userId, type);
        return new ApiReturnObject("201", "");
    }

    /**
     * 查询分享内容  左侧目录
     */
    @GetMapping("/shareList")
    public ApiReturnObject shareList(Integer catalogId) {
        //  查看班级字符串   是否同步  学生查看     名称拼接
        //内容字符串拼接
        //查看班级字符串拼接
        if (catalogId != null) {
            SAnswering answering = new SAnswering();
            //该目录下课程问答列表
//            List<SAnswering> sAnswerings = answeringService.selectSAnsweringList(answering);
            //该资源集合的查看班级
            /*List<TClass> classList = answerClass2(catalogId);
            if (classList != null && classList.size() > 0) {
                answering.setClassList(classList);
                String s = "";
                int size = classList.size();
                //拼接查看班级字符串
                for (int i = 0; i < size; i++) {
                    if (i == size - 1) {
                        //最后一个
                        s = s + classList.get(i).getClassName();
                    } else {
                        s = s + classList.get(i).getClassName() + ",";
                    }
                }
                answering.setCheckString(s);
            }*/
            //查看内容
            List<SAnswering> sAnswerings1 = lookContent(catalogId);
            //是否同步  和   允许学生查看
            if (sAnswerings1 != null && sAnswerings1.size() > 0) {
                String s = "";
                int size = sAnswerings1.size();
                for (int i = 0; i < sAnswerings1.size(); i++) {
                    //查看内容字符串拼接
                    if (i == size - 1) {
                        //最后一个
                        s = s + sAnswerings1.get(i).getProblemTitle();
                    } else {
                        s = s + sAnswerings1.get(i).getProblemTitle() + ",";
                    }
                    answering.setAnsTitleString(s);
                    //是否同步
                    if (sAnswerings1.get(0).getSynch() != null) {
                        if ("0".equals(sAnswerings1.get(0).getSynch())) {
                            answering.setSynchBool(false);
                        } else if ("1".equals(sAnswerings1.get(0).getSynch())) {
                            answering.setSynchBool(true);
                        }
                    }
                    //是否允许学生查看
                    if (sAnswerings1.get(0).getIsStu() != null) {
                        if ("0".equals(sAnswerings1.get(0).getIsStu())) {
                            answering.setStuBool(false);
                        } else if ("1".equals(sAnswerings1.get(0).getIsStu())) {
                            answering.setStuBool(true);
                        }
                    }
                }
            }
            return new ApiReturnObject("200", "查询成功", answering);
        }
        return new ApiReturnObject("201", "缺少catalogId", "");
    }

    /**
     * 对分享模块进行操作
     */
    @PostMapping("/share")
    public ApiReturnObject share(@RequestBody SAnswering answering) {
        // 查看内容
        if (answering.getAnsweringList() != null && answering.getAnsweringList().size() > 0) {
            if (answering.getCatalogId() != null) {
                // 左侧第几讲的课程id 和 课程问答id
                SCatalogAnsweringSyn catalogAnsweringSyn = new SCatalogAnsweringSyn();
                catalogAnsweringSyn.setCatalogId(answering.getCatalogId());
                catalogAnsweringSyn.setCreateTime(new Date());
                for (SAnswering sAnswering : answering.getAnsweringList()) {
                    catalogAnsweringSyn.setAnsweringId(sAnswering.getId());
                    // 往中间表里添加数据
                    catalogAnsweringSynService.insertSCatalogAnsweringSyn(catalogAnsweringSyn);
                }
                return new ApiReturnObject("200", "分享成功", "");
            }
            return new ApiReturnObject("201", "缺少catalogId参数", "");
        }
        return new ApiReturnObject("201", "请选择要分享的课程问答", "");
    }

    /**
     * 修改此门备课的状态
     */
    public SCatalogMenu changeStatus(SAnswering answering) {
        //将资源所在的备课状态改变
        Integer rCatalogId = answering.getCatalogId();
        //教师创建课程表
        SCatalogMenu sCatalog = catalogMenuService.selectSCatalogMenuById(rCatalogId);
        //目录最下面一级
        Integer parentId = sCatalog.getParentId();
        //备课课程id
        Integer integer = GetFirstId2(parentId);
        SCatalogMenu catalogMenu = catalogMenuService.selectSCatalogMenuById(integer);
        return catalogMenu;
    }

    public SAnswering updateStatus(SAnswering answering) {
        //app 端查看 允许
        String i = "1";
        if (i.equals(answering.getIsStu())) {
            SCatalogMenu catalogMenu = changeStatus(answering);
            if (!i.equals(catalogMenu.getIsStu())) {
                //修改备课是否允许学生查看状态
                catalogMenu.setIsStu("1");
                catalogMenuService.updateSCatalogMenu(catalogMenu);
            }
        }
        // 同步到上课资料
        if (i.equals(answering.getSynch())) {
            //同步上课资料
            SCatalogMenu catalogMenu = changeStatus(answering);
            if (!i.equals(catalogMenu.getIsSyn())) {
                //修改同步上课资料状态
                catalogMenu.setIsSyn("1");
                catalogMenuService.updateSCatalogMenu(catalogMenu);
            }
        }
        return answering;
    }


    /**
     * 修改课程问答
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody SAnswering answering) {
//        if(answering.getId() != null){
        //修改某个字段 避免空值报错 针对于查看内容中的课程问答状态
        //修改 查看内容 状态  修改上级
        if (answering.getCatalogId() != null) {
            updateStatus(answering);
        }
        if (answering.getContentList() != null && answering.getContentList().size() > 0) {
            for (SAnswering answering1 : answering.getContentList()) {
                if (answering.getIsStu() != null && !"".equals(answering.getIsStu())) {
                    answering1.setIsStu(answering.getIsStu());
                }
                if (answering.getSynch() != null && !"".equals(answering.getSynch())) {
                    answering1.setSynch(answering.getSynch());
                }
                answeringService.updateSAnswering(answering1);
            }
        }
        answering.setIsdisplay("1");
        //修改是否允许学生查看    是否同步上课资料
        answeringService.updateSAnswering(answering);
        return new ApiReturnObject("200", "修改成功", "");
//        }
//        return new ApiReturnObject("201","缺少id","");
    }

    /**
     * 修改课程问答
     */
    @PostMapping("/updateData")
    public ApiReturnObject updateData(@RequestBody SAnswering answering) {
        if (answering.getId() != null) {
            //修改是否允许学生查看    是否同步上课资料
            answeringService.updateSAnswering(answering);
            return new ApiReturnObject("200", "修改成功", "");
        }
        return new ApiReturnObject("201", "缺少id", "");
    }


    /**
     * 备课模块-课堂答疑主键删除
     *
     * @param answering
     * @return
     */
    @PostMapping("/del")
    public ApiReturnObject remove(@RequestBody SAnswering answering) {
        if (answering.getId() != null) {
            Integer AnswerNum = sAnsweringCommentService.countEachAnswerTalkNum(answering.getId());
            if (AnswerNum > 0) {
                return new ApiReturnObject("201", "参与讨论后禁止删除", "");
            }
            answeringService.deleteSAnsweringById(answering.getId());
            return new ApiReturnObject("200", "删除成功", "");
        }
        return new ApiReturnObject("201", "缺少id", "");
    }


}